<template>
	<view class="mainpadding2" style="padding-bottom: 150rpx;">
		<u-navbar title="節假日價格" placeholder autoBack>
			<view class="flexright xiaohui" slot="right" @click="jumpurl('/pages/workbench/tianjiajjrjg')">添加</view>
		</u-navbar>
		<view class="flexcenter" v-if="!list.length">
			<view class="placeholderimage" style="margin-top: 100rpx;"></view>
		</view>
		<view class="mainpadding_top ffffff radius dingwei" v-for="item in list" :key="item.id" @click="checkitem(item)">
			<view class="checkfocus" v-if="item.ischeck">
				<u-icon name="checkbox-mark" color="#fff" size="16"></u-icon>
			</view>
			<view class="flexbetween">
				<view class="titletext xiaohuang bold">{{item.name}}</view>
			</view>
			<view class="main_size xiaohei margin_top">設定日期</view>
			<view class="flexleft flex-wrap">
				<view class="xiaohui margin_top2 margin_right1 riqik" v-for="ite in item.date_time_text" :key="ite">{{ite}}</view>
			</view>
			<view class="flexright margin_top">
				<view class="flexleft margin_left" @click.stop="jumpdetail('/pages/workbench/tianjiajjrjg?id=',item.id)">
					<u-icon name="edit-pen" color="#999" size="16"></u-icon>
					<view class="xiaohei">編輯</view>
				</view>
				<view class="flexleft margin_left" @click.stop="delitem(item.id)">
					<u-icon name="trash" color="#999" size="16"></u-icon>
					<view class="xiaohei">刪除</view>
				</view>
			</view>
		</view>
		<view class="posibottom mainpadding" v-if="type==1">
			<view class="submitbtn" @click="submit">確定</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				type:0
			}
		},
		onLoad(options) {
			if(options.type){
				this.type = options.type
			}
		},
		onShow() {
			this.getjgList()
		},
		methods: {
			submit() {
				let jjrprice_data = JSON.parse(JSON.stringify(this.list))
				let arr = []
				jjrprice_data.forEach(item=>{
					if(item.ischeck){
						arr.push({
							shoptable_jjrprice_id:item.id,
							name:item.name,
							date_time_text:item.date_time_text,
							cb_price:item.cb_price,
							dz_price:item.dz_price,
							yc_price:item.yc_price,
							xx_price:item.xx_price,
							zs_price:item.zs_price
						})
					}
					
				})
				uni.$emit("checkjjrjg", arr)
				uni.navigateBack(1)
			},
			checkitem(item) {
				if (this.type == 1) {
					item.ischeck = !item.ischeck
				}
			},
			getjgList() {
				this.http.request("/api/hotel/jjrpriceIndex", 'GET', {
					page:1,
					limit:1000,
					shop_id: uni.getStorageSync("shop_id")
				}).then(res => {
					res.data.data.forEach(item => {
						this.$set(item, "ischeck", false)
					})
					this.list = res.data.data
				})
			},
			delitem(id) {
				this.http.modal('提示', '確認刪除當前數據嗎？', true, (res) => {
					if (res) {
						this.http.request("/api/hotel/delJjrprice", 'GET', {
							id
						}).then(res => {
							if (res.code == 1) {
								this.http.toast("刪除成功")
								this.getjgList()
							} else {
								this.http.toast(res.msg);
							}
						})
			
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.riqik{
		border: 1rpx solid #999;
		padding: 5rpx 10rpx;
	}
</style>